package main

import (
	"fmt"
	"time"

	"adkr/pkg/adkr"
	"adkr/pkg/crypto"
)

func main() {
    fmt.Println("=== ACSS simple test ===")
    
    // Set Secp256k1
	crypto.SetCurveType(crypto.Secp256k1)
	
    // Test parameters
	n := 4
	f := 1
	pid := 0
	dealer := 0
	
    // Create message channels
	msgInCh := make(chan adkr.Message, 100)
	msgOutCh := make(chan adkr.Message, 100)
	outputCh := make(chan adkr.ACSSOutput, 1)
	
    // Start ACSS
	go adkr.CompleteSecretSharing(
		"test-acss",
		pid, n, f, []int{0, 1, 2, 3}, // old config
		n, f, []int{0, 1, 2, 3}, // new config
		&crypto.G1{}, &crypto.G1{}, // g, h
		dealer,
		[]crypto.G1{}, crypto.ZR{}, // ePKs, eSK
		nil, // inputCh
		outputCh,
		msgInCh,
		msgOutCh,
	)
	
    // Simulate message passing
	go func() {
		for msg := range msgOutCh {
            fmt.Printf("ACSS send: Tag=%d, Round=%d, To=%d\n", msg.Tag, msg.Round, msg.To)
            // Simulate routing to other nodes
			if msg.To == -1 {
                // Broadcast to all nodes
				for i := 0; i < n; i++ {
					if i != pid {
						msgCopy := msg
						msgCopy.To = i
						select {
						case msgInCh <- msgCopy:
						default:
						}
					}
				}
			} else {
                // Unicast
				select {
				case msgInCh <- msg:
				default:
				}
			}
		}
	}()
	
    // Wait for result
	select {
	case output := <-outputCh:
        fmt.Printf("ACSS completed: %+v\n", output)
	case <-time.After(10 * time.Second):
        fmt.Println("ACSS timeout")
	}
}
